<?php
/**
 * NetBiz Framework
 * Copyright (C) 20009 - 2010 NetBiz
 * 
 * All rights reserved.
 */
 
require_once 'Log.php';

/**
 * Base class for logger messages decorators
 */
class FRM_Log_DecoratorStandard extends FRM_Log_Decorator {
	function __toString()
	{
		$m = parent::__toString();

		// Adding the debug information
		// Adding the filename and line number from which the log function was called

		// But first, find the initial level
		$depth = 3;
		$dbt = debug_backtrace();

		// Have we call directly log or a shorcut function?
		if ($dbt[$depth+1]['class'] == 'FRM_Log')
		{
			++$depth;
		}
		// Have we called from FRM_DataObjects ?
		if (basename($dbt[$depth]['file']) == 'FRM_DataObject.php')
		{
			++$depth;
		}

		$m = '['.substr(strtoupper(Log::priorityToString($this->_priority)),0,4) . '] ' .
			'('.basename($dbt[$depth]['file']).':'.$dbt[$depth]['line'].') ' .
			'('.(isset($dbt[$depth+1]['object'])?get_class($dbt[$depth+1]['object']).'.':'STATIC_CALL.') .
			(isset($dbt[$depth+1]['function'])?$dbt[$depth+1]['function']:'MAIN').') ' .
			$m;

		return $m;
	}
}